package com.atldy.commerce.controller;

import com.atldy.commerce.service.OpenfeignTokenService;
import com.atldy.commerce.service.RibbonService;
import com.atldy.commerce.service.UserRestTemplateService;
import com.atldy.commerce.vo.JwtToken;
import com.atldy.commerce.vo.UsernameAndPassword;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0
 * @Author: li-dong-yang
 * @CreateTime: 2021-08-24 6:24
 * @Description：
 */
@RestController
@RequestMapping("/rest")
public class UserTemplateController {

    @Autowired
    private UserRestTemplateService userRestTemplateService;

    @Autowired
    private RibbonService ribbonService;

    @Autowired
    private OpenfeignTokenService openfeignTokenService;

    @PostMapping("/getJwtToken")
    public JwtToken getJwtToken(@RequestBody UsernameAndPassword usernameAndPassword) {
        return userRestTemplateService.getToken(usernameAndPassword);
    }

    @PostMapping("/getTokenLoadBalancerC")
    public JwtToken getTokenLoadBalancerC(@RequestBody UsernameAndPassword usernameAndPassword) {
        return userRestTemplateService.getTokenLoadBalancerC(usernameAndPassword);
    }

    /**
     * 使用ribbon请求服务
     */
    @PostMapping("/getRestJwtToken")
    public JwtToken getRestJwtToken(@RequestBody UsernameAndPassword usernameAndPassword) {
        return ribbonService.getRestJwtToken(usernameAndPassword);
    }

    /**
     * 使用ribbon请求服务
     */
    @PostMapping("/getOpenfeignToken")
    public JwtToken getOpenfeignToken(@RequestBody UsernameAndPassword usernameAndPassword) {
        return openfeignTokenService.getOpenfeignToken(usernameAndPassword);
    }



}